import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
//列表数据
export const columns: BasicColumn[] = [
   {
    title: '算法编码',
    align:"center",
    dataIndex: 'algorithmCode'
   },
   {
    title: '算法名称',
    align:"center",
    dataIndex: 'algorithmName'
   },
   {
    title: '算法描述',
    align:"center",
    dataIndex: 'algorithmDescribe'
   },
   {
    title: '算法分析类型',
    align:"center",
    dataIndex: 'analyType_dictText'
   },
   {
    title: '算法状态',
    align:"center",
    dataIndex: 'algorithmStatus_dictText'
   },
   {
    title: '算法小类编码',
    align:"center",
    dataIndex: 'algorithmMinTypeCode_dictText'
   },
   {
    title: '厂家编码',
    align:"center",
    dataIndex: 'factoryCode_dictText'
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
     {
      label: "算法编码",
      field: "algorithmCode",
      component: 'Input', //TODO 范围查询
      //colProps: {span: 6},
	},
     {
      label: "算法名称",
      field: "algorithmName",
      component: 'Input', //TODO 范围查询
      //colProps: {span: 6},
	},
	{
      label: "算法分析类型",
      field: 'analyType',
      component: 'JSelectMultiple',
      componentProps:{
          dictCode:"analy_type"
      },
      //colProps: {span: 6},
 	},
	{
      label: "算法状态",
      field: 'algorithmStatus',
      component: 'JSelectMultiple',
      componentProps:{
          dictCode:"valid_status"
      },
      //colProps: {span: 6},
 	},
	{
      label: "算法小类编码",
      field: 'algorithmMinTypeCode',
      component: 'JSearchSelect',
      componentProps:{
         dict:"tbl_algorithm_type where type_level='3',type_name,type_code"
      },
      //colProps: {span: 6},
 	},
	{
      label: "厂家编码",
      field: 'factoryCode',
      component: 'JSearchSelect',
      componentProps:{
         dict:"tbl_factory_info,factory_name,factory_code"
      },
      //colProps: {span: 6},
 	},
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '算法编码',
    field: 'algorithmCode',
    component: 'Input',
    dynamicDisabled:true,
    //渲染 values当前表单所有值
    render: ({ values }) => {
      let factoryCode = values.factoryCode;
      let algorithmMinTypeCode = values.algorithmMinTypeCode;
      let analyType = values.analyType;
      let algorithmCode = factoryCode+'-'+algorithmMinTypeCode+'00'+analyType;
      return factoryCode && algorithmMinTypeCode && analyType ?algorithmCode : '';

    },
  },
  {
    label: '算法名称',
    field: 'algorithmName',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入算法名称!'},
          ];
     },
  },
  {
    label: '算法描述',
    field: 'algorithmDescribe',
    component: 'Input',
  },
  {
    label: '算法分析类型',
    field: 'analyType',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"analy_type"
     },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入算法分析类型!'},
          ];
     },
  },
  {
    label: '算法状态',
    field: 'algorithmStatus',
    component: 'JDictSelectTag',
    componentProps:{
        dictCode:"valid_status",
        type: "radio"
     },
  },
  {
    label: '算法小类编码',
    field: 'algorithmMinTypeCode',
    component: 'JSearchSelect',
    componentProps:{
       dict:"tbl_algorithm_type where type_level='3',type_name,type_code"
    },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入算法小类编码!'},
          ];
     },
  },
  {
    label: '厂家编码',
    field: 'factoryCode',
    component: 'JSearchSelect',
    componentProps:{
       dict:"tbl_factory_info,factory_name,factory_code"
    },
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入厂家编码!'},
          ];
     },
  },
	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];

// 高级查询数据
export const superQuerySchema = {
  algorithmCode: {title: '算法编码',order: 0,view: 'text', type: 'string',},
  algorithmName: {title: '算法名称',order: 1,view: 'text', type: 'string',},
  algorithmDescribe: {title: '算法描述',order: 2,view: 'text', type: 'string',},
  analyType: {title: '算法分析类型',order: 3,view: 'list', type: 'string',dictCode: 'analy_type',},
  algorithmStatus: {title: '算法状态',order: 4,view: 'radio', type: 'string',dictCode: 'valid_status',},
  algorithmMinTypeCode: {title: '算法小类编码',order: 5,view: 'sel_search', type: 'string',dictTable: "tbl_algorithm_type where type_level='3'", dictCode: 'type_code', dictText: 'type_name',},
  factoryCode: {title: '厂家编码',order: 6,view: 'sel_search', type: 'string',dictTable: "tbl_factory_info", dictCode: 'factory_code', dictText: 'factory_name',},
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
